import Vue from "vue";
import Router from "vue-router";
import menu from "./menu";
import store from "../store";
import el from "element-ui/src/locale/lang/el";
// import qs from "qs";
Vue.use(Router);
const newRouter = new Router({
    mode: "hash",
    routes: menu
});

newRouter.beforeEach((to, from, next) => {
    window.scrollTo(0,0);
    if (to.matched.some(res => res.meta.requireAuth) || to.path == "/"){
        if (store.state.islogin){
            console.log('to.path>>> ',to.path)
            if (to.path == "/"){
                next({ path: "/index" })
            }else{
                next()
            }
        }else{
            next({ path: "/login" })
        }
    }else{
        if (to.path.toString().indexOf('login') !==-1){
            if (store.state.islogin){
                next({path:'/index'})
            }else{
                next()
            }
        }
        next()
    }

})

export default newRouter;